import { storeBindingsBehavior } from 'mobx-miniprogram-bindings'
import member from "@src/store/member";
import router from "@src/router";
import {updatePhone} from '@src/api/member'

Component({
  behaviors: [storeBindingsBehavior, router.routerBehavior],
  storeBindings: [{
    store: member,
    fields: ['isMember', 'phone'],
    actions: ['getBaseInfo'],
  }],
  data: {
    versionNum: "",
  },
  methods: {
    onLoad() {
      let versionNum = getApp().globalData.extConfig.versionNum;
      this.setData({'versionNum': versionNum})
    },
    getPhone(e) {
      console.info("getPhoneNumber", e)
      if (!e.detail.iv) {
        wx.showToast({title: "手机号获取失败，请重试", icon: "none", duration: 1500});
        return;
      }
      let data = {
        ivStr: e.detail.iv,
        encryptedData: e.detail.encryptedData,
      }
      updatePhone(data).then(res => {
        // 刷新
        this.getBaseInfo();
      })
    }
  }
})
